package model.forview;

import java.util.Iterator;
import java.util.Map;


import models.ConstantName;
import models.ConstantValue;

public class LoginModelForView extends ContentForMainTemplate
{
    public String email ;
    public String password ;

    public String emailLabel;
    public String passwordLabel;
    public String saveButton;
    public String cancelButton;

    public final String emailName = "email";
    public final String passwordName = "password";

    public void setDefaultValues()
    {
	String title = ConstantValue
		.getConstantValue(ConstantName.LOGIN_PAGE_TITLE);
	String header = ConstantValue
		.getConstantValue(ConstantName.LOGIN_PAGE_HEADER);
	String footer = ConstantValue
		.getConstantValue(ConstantName.LOGIN_PAGE_FOOTER);
	String userName = "";

	emailLabel = ConstantValue.getConstantValue(ConstantName.EMAIL);
	passwordLabel = ConstantValue.getConstantValue(ConstantName.PASSWORD);
	saveButton = ConstantValue.getConstantValue(ConstantName.SAVE_BUTTON);
	cancelButton = ConstantValue.getConstantValue(ConstantName.CANCEL_BUTTON);

	emailLabel = emailLabel != null ? emailLabel : "Email";
	passwordLabel = passwordLabel != null ? passwordLabel : "Password";
	saveButton = saveButton != null ? saveButton : "Save";
	cancelButton = cancelButton != null ? cancelButton : "Cancel";

	title = title != null ? title : "Вход в систему";
	header = header != null ? header : "Требуется авторизоваться для входа";
	footer = footer != null ? footer : "Страница авторизации пользователей";

	mainModelForView = new MainModelForView(title, userName, header, footer);
    }

    public LoginModelForView()
    {
	setDefaultValues();
    }
    
    public LoginModelForView(Map<String, String> form)
    {
	Iterator<String> keys = form.keySet().iterator();
	while(keys.hasNext())
	{
	    String key = keys.next();
	    if(key.equals("data["+this.emailName+"]"))
		this.email = form.get(key);
	    if(key.equals("data["+this.passwordName+"]"))
		this.password = form.get(key);
	}
    }
}
